import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import LoginView from "@/views/LoginView";
import SearchPopup from "@/views/SearchPopup";
import productDetail from "@/views/productDetail";
import User from "@/views/User";
import Cart from "@/views/Cart";
import Label from "@/views/Label";
import Apps from "@/views/Apps";
import Channel from "@/views/Channel"
Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, resolve, reject) {
    if (resolve || reject) return originalPush.call(this, location, resolve, reject)
    return originalPush.call(this, location).catch(() => {
    })
}


const routes = [
    {
        // 主页
        path: '/',
        name: 'home',
        component: HomeView,
        children: [
            {
                path: 'searchPopup',
                name: 'SearchPopup',
                component: SearchPopup,
            },
        ],
        meta: {
            num: 0,
            //判断Tabbar是否显示 在顶级组件App.vue中 <AppTabbar v-show='$route.meta.isShowAppTabbar'/>
        }

    },
    {
        //登录
        path: '/login',
        name: 'Login',
        component: LoginView
    },
    {
        //产品详情页
        path: "/productDetail",
        name: "ProductDetail",
        component: productDetail
    },
    {
        // 用户
        path: "/user",
        name: "user",
        component: User,
        meta: {
            num: 4,
        }
    },
    {
        //购物车
        path: "/cart",
        name: "Cart",
        component: Cart,
        meta: {
            num: 3,
        }
    },
    {
        //专题
        path: "/label",
        name: "label",
        component: Label,
        meta: {
            num: 1,
            //判断Tabbar是否显示 在顶级组件App.vue中 <AppTabbar v-show='$route.meta.isShowAppTabbar'/>
        }
    },
    {
        //分类
        path: "/apps",
        name: "Apps",
        component: Apps,
        meta: {
            num: 2,
        }
    },
    {
        path: "/channel",
        name: "Channel",
        component: Channel,
    }
]

const router = new VueRouter({
    mode: "hash",
    routes
})

export default router
